Nested Comments

This page has been superceded by a wiki version of this example: NestedCommentsExample

This program doesn't do anything, but it's well-documented.



/* 



nested_comments.html 



Author: J C Calvarese

License: public domain



This program demonstrates using comments in D.



(Such as the multi-line comment this sentence resides in.)



*/







/+   



    This is one of D's nested comments.  





    /+ What would an example of a nested comment be without 

       a nested (and /+ another nest +/ )comment? +/



    /* Naturally, you can also put something like this in a nested multiline comments... */



    // as well as text like like this ...



	/* since the compiler is only concerned about being in a nested comment block,

		you don't actually need a matching * and / to satisfy the compiler.



+/







void main()  

{ // This is a single line comment.  It automatically ends at the end of the line.

}



Review of Comments in D

There are three different kinds of comments in D:

  1. Single-line comments (//): These comments can start anywhere except in the middle of a token and continue until the end of the line.
  2. Regular multi-line comments (/* */): These comments can occur anywhere except within a token or another regular multi-line comments.
  3. Nesting multi-line comments (/+ +/): These comments can occur anywhere except within a token. Whenever the compiler sees an initial marker (/+), it goes into "nesting comments" mode. At this point, the compiler is only looking for two things another initial marker to indicate a deeper nested comment or a terminal marker (+/) to close a nesting level. The compiler ignores other symbols within nested comments including quotes(""), multi-line comments (/* */), and single-line comments (//).


Return to Tutorial Overview